import { Component, OnInit } from '@angular/core';
import {NzModalService} from 'ng-zorro-antd';
import {Router} from '@angular/router';
import cookie from '../../common/utils/cookie';
import getData_ajax from '../../common/utils/getData_ajax';
import config from '../../common/utils/baseUrl';

@Component({
  selector: 'app-dashboard',
  templateUrl: './dashboard.component.html',
  styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit {
  public isSpinning:any = true; // 加载状态
  public ariticeData:any = []; // 文章数据
  constructor(private modalService: NzModalService,private router: Router) { }

  ngOnInit() {
    let _this = this;
    // 根据 localStorage 判断用户是否登录
    if(!cookie.getCookie("isLogin")){
      _this.modalService.error({
        nzTitle: '错误',
        nzContent: '小哥哥，小姐姐你还没登录呢...'
      });
      setTimeout(()=>{
        _this.router.navigateByUrl("/back/login");
      }, 2000)
    }

    this.getData();
  }

  // 拉取数据
  getData(){
    let _this = this;
    getData_ajax.getFunc(config.baseUrl+'/articleService/getArticeData','post','',function(data){
        _this.ariticeData = data;
        _this.isSpinning = false;
      },
      function(error){
        console.log(error)
      })
  }

}
